﻿using System.Xml.Linq;
using Maple.Weixin.MP.Helpers;

namespace Maple.Weixin.MP.Entities.Messages
{
    public class RequestMessageVoice : RequestMessageBase
    {
        public override RequestMessageType MsgType
        {
            get { return RequestMessageType.Voice; }
        }

        public string MediaId { get; private set; }
        /// <summary>
        /// 语音格式：amr
        /// </summary>
        public string Format { get; private set; }
        /// <summary>
        /// 语音识别结果，UTF8编码
        /// 开通语音识别功能，用户每次发送语音给公众号时，微信会在推送的语音消息XML数据包中，增加一个Recongnition字段。
        /// 注：由于客户端缓存，开发者开启或者关闭语音识别功能，对新关注者立刻生效，对已关注用户需要24小时生效。开发者可以重新关注此帐号进行测试。
        /// </summary>
        public string Recognition { get; private set; }

        protected override void FillPropertiesByXml(XDocument document)
        {
            base.FillPropertiesByXml(document);
            this.MediaId = document.GetElementValue("MediaId", true);
            this.Format = document.GetElementValue("Format", true);
            this.Recognition = document.GetElementValue("Recognition", true);
        }

        public override T Accept<T>(RequestMessageVisitor<T> visitor) {
            return visitor == null ? default(T) : visitor.Visit(this);
        }
    }
}
